
#define SysTime_Variable
#include "userDef.h"
U16     MotorErr = 0; // 反馈信号电平 直流电机错误


void DcMotorTimeCount( void )
{
    if (( fan_timer.speedBack1 >= 10000 )&&(speedSetValue > 0)&&( e_fanStep.run != FANSTOP )) // 没有反馈信号，风机报错  if ( fan_timer.speedBack1 >= 0x0200 )
    {
        MotorErr = 1;
    }
}


void SysTime0P5ms( void )
{
    Timer5msCount++;
    Timer10msCount++;
    DcMotorTimeCount();                 // 直流电机没有反馈信号 计时

#ifdef CTRL_485
    if ( comm485.timeout_rxd > 0 )
    {
        comm485.timeout_rxd--;
    }

#endif

    if ( e_fanStep.run != FANSTOP )
    {
        if ( fan_timer.speedBack1 <= 0xFFFF )   // if ( fan_timer.speedBack1 <= 0x0210 )
        {
            fan_timer.speedBack1++;
        }

        if ( fan_timer.speedBack2 <= 0xFFFF )   // if ( fan_timer.speedBack2 <= 0x0210 )
        {
            fan_timer.speedBack2++;
        }
    }

#ifdef PG_MOTOR
    if ( fan_timer.ZeroCheck <= 250 )
    {
        fan_timer.ZeroCheck++;
    }

#endif

    SwingDriver();
    commwifiTime();
    if ( CommInOut_Type1 == 0 )
    {
        Tm_500us_CommInOut_MB();
    }
    else 
    {
        CommInOut_timer_500us();
    }
}


void SysTime5ms( void )
{
    if ( Timer5msCount >= 10 )
    {
        Timer5msCount -= 10;

#ifdef DISP_HC164
        DispDriver();
#endif // DISP_HC164
    }
}


void SysTime10ms( void )
{
    if ( Timer10msCount >= 20 )
    {
        Timer10msCount -= 20;
        Timer100msCount++;
        if ( Timer100msCount >= 10 )
        {
            Timer100msCount -= 10;
            SysTime100ms();
            if ( PerformanceTest.PerformanceTestOccurFlag == 1 )
            {
                if ( ++PerformanceTest.DisPlayRefreshCount >= 10 )
                {
                    PerformanceTest.DisPlayRefreshCount = 0;
                }			   
            }
        }

        KeyJudge();
        ADConvert();
        BuzzerTime();
        InsideTest_CustomerTimeSlics();
        EntranceGuard.DoorFlag = GetDoorState(); // 门开关状态读取
        if ( fan_timer.adj < 50 )
        {
            fan_timer.adj++;
        }
    }
}


void SysTime100ms( void )
{
    Timer1sCount++;
    if ( Timer1sCount >= 10 )
    {
        Timer1sCount -= 10;
        SysTime1s();
        PerformanceTestDelay();
        EntranceGuardPressScreenDisplayTime();
        EntranceGuardFucDiplay();       // 门开关计时
    }

    Timer1sQTCount += Norm01Fast05;
    if ( Timer1sQTCount >= 10 )
    {
        Timer1sQTCount -= 10;
        SysTime1sQT();
    }

    if ( timer_wifi.ota_delay > 0 )
    {
        timer_wifi.ota_delay--;
        if ( timer_wifi.ota_delay == 0 )
        {
            // DI();
            // WDTE = 0xAAU;
        }
    }

    if ( timer_powerOn <= 50 )
    {
        timer_powerOn++;
    }

    if ( timer_CommInOut.tsreset > 0 )
    {
        timer_CommInOut.tsreset--;
    }

    if ( CtrlEndTime < 50 )
    {
        CtrlEndTime++;
    }

    if ( timer_FoRecall_Set > 0 )
    {
        timer_FoRecall_Set--;
    }

    if ( timer_wifi.upd_5s > 0 )
    {
        timer_wifi.upd_5s--;
    }
    else 
    {
        timer_wifi.upd_5s = 50;
        device_data_upd_all_5s = 0xFF;
    }

    if ( timer_wifi.upd_3s > 0 )
    {
        timer_wifi.upd_3s--;
    }
    else 
    {
        timer_wifi.upd_3s = 50;
        device_data_upd_all_3s = 0xFF;
    }

    if ( timer_wifi.upd_2s > 0 )
    {
        timer_wifi.upd_2s--;
    }
    else 
    {
        timer_wifi.upd_2s = 50;
        device_data_upd_all_2s = 0xFF;
    }

#ifdef HTU20_SENSOR
    Readhtu20();
#endif

    DisplayTime();
    TestSetTime();
    HeaterLowTime();
}


void SysTime1s( void )
{
    EntranceGuard_SysTime();
    if ( WakeUpSec > 0 )
    {
        WakeUpSec--;
    }

    if ( AutoModeUpdSec > 0 )
    {
        AutoModeUpdSec--;
    }

    if ( compOnRandomSet < 15 )
    {
        compOnRandomSet++;
    }
    else 
    {
        compOnRandomSet = 0;
    }

    if ( ForceDefSec > 0 )
    {
        ForceDefSec--;
    }

    if ( TestRunStat != 0 || ForceDefSec == 0 )
    {
        set_manual_defrost( OFF );
        ForceDefSec = 0;
    }

    if ( PowerOnSec < 59 && PowerOnMin < 10 )
    {
        PowerOnSec++;
    }
    else 
    {
        if ( PowerOnMin < 10 )
        {
            PowerOnSec = 0;
            PowerOnMin++;
        }
    }

#ifndef KONGKE

#ifdef HEATER_ERR
    HeaterErrCheck();
#endif

#endif

#ifdef GAS_SENSOR
    gas_sensor_check();
#endif
}


void SysTime1sQT( void )
{
    if ( Pump_1.Min_1_Falg == 1 ) // 鍏虫満姘存车寤舵椂鍏抽棴
    {
        if ( ( f_waterErr == TRUE ) || ( ( b_power.run == ON ) && ( ( e_mode.run == MODECOOL ) || ( e_mode.run == MODEDRY ) ) ) ) // 如果1分内检测到水满或者
        {
            if (( ( e_mode.run == MODECOOL ) || ( e_mode.run == MODEDRY ) )&&(f_RoomUnitOn == ON ))
            {
                Pump_1.Min_1_CorrelationCoolDryFlag = 1;
            }
            else if ( f_waterErr == TRUE )
            {
                Pump_1.Min_1_CorrelationWaterFullFlag = 1;
            }
        }

        if ( ++Pump_1.Min_1_Count > 60 )
        {
            Pump_1.OnOrOff = 0;
            Pump_1.Min_1_Falg = 0;
            Pump_1.Min_1_Count = 0;
        }
    }

    if ( timer_IFeelSec > 0 )
    {
        timer_IFeelSec--;
    }

    if ( HeatOffBlowSec > 0 )
    {
        HeatOffBlowSec--;
    }

    if ( HeatOverBlowSec > 0 )
    {
        HeatOverBlowSec--;
    }

    if ( CommJudgeTime > 0 )
    {
        CommJudgeTime--;
    }

#ifdef CTRL_485
    if ( timer_room_mode_wireCtrl > 0 )
    {
        timer_room_mode_wireCtrl--;
    }
    else 
    {
        room_mode_wireCtrl = 0;
    }

    if ( timer_wireCtrl_err > 1 )
    {
        timer_wireCtrl_err--;
    }
    else if ( timer_wireCtrl_err == 1 )
    {
        f_comm485Err = ON;
    }

#endif

    if ( b_power.run == ON && e_fanStep.set[e_mode.set] == FANAUTO && e_fanStep.run != FANSTOP )
    {
        if ( timer_AFanUpdSec >= Norm01Fast30 )
        {
            timer_AFanUpdSec -= Norm01Fast30;
        }
        else 
        {
            timer_AFanUpdSec = 0;
        }
    }
    else 
    {
        timer_AFanUpdSec = 0;
    }

    if ( e_mode.set == MODEAUTO )
    {
        if ( autoMode.timer >= Norm01Fast05 )
        {
            autoMode.timer -= Norm01Fast05;
        }
        else 
        {
            autoMode.timer = 0;
        }
    }

    if ( e_fanStep.run != FANSTOP )
    {
        if ( fan_timer.chg < 220 )
        {
            fan_timer.chg += Norm01Fast30;
        }
    }
    else 
    {
        fan_timer.chg = 0;
    }

    FoRecallTime();
    CleanSelfAct();
    antidewingTime();
    if ( CommInOut_Type1 == 0 )
    {
        ;
    }
    else 
    {
        CommInOut_time_1s();
    }

    TimerWakeUp();
    OutPowerTime();
    FanRunTime();
    SleepTime();
    HeaterOffTime();
    AvoidColdTime();
    CompTime();
    DefEndTime();
    DryerTime();
    FanMotorTime();
    EcoActTime();
    CallDispTime();
    TimerOnOff();

//#ifdef PUMP
    Pump_timer_1s();
//#endif

    DisplayTime_1s();
    if ( CommInOut_Type1 == 0 )
    {
        Tm_1s_CommInOut_MB();
    }
}


void CompTime( void )
{
    if ( f_RoomUnitOn == 1 )
    {
        CompOffSec = 0;
        CompOffSumSec = 0;
        CompOffSumMin = 0;
        CompOnSumSec++;
        if ( CompOnSumSec >= Norm60Fast02 )
        {
            CompOnSumSec = 0;
            if ( CompOnSumMin < 250 )
            {
                CompOnSumMin++;
            }
        }
    }
    else 
    {
        CompOnSumSec = 0;
        CompOnSumMin = 0;
        CompOffSumSec++;
        if ( CompOffSumSec >= Norm60Fast02 )
        {
            CompOffSumSec = 0;
            if ( CompOffSumMin < 70 )
            {
                CompOffSumMin++;
            }
        }

        if ( CompOffSec < 0xF0 )
        {
            CompOffSec += Norm01Fast30;
        }
    }
}


void DefEndTime( void )
{
    if ( f_Defrosting == 1 )
    {
        DefEndSec = 0;
        DefEndMin = 5;
    }
    else 
    {
        if ( DefEndMin > 0 )
        {
            DefEndSec += Norm01Fast30;
            if ( DefEndSec >= Norm60Fast02 )
            {
                DefEndSec = 0;
                if ( DefEndMin >= Norm01Fast05 )
                {
                    DefEndMin -= Norm01Fast05;
                }
                else 
                {
                    DefEndMin = 0;
                }
            }
        }
    }
}


void CallDispTime( void )
{
    if ( CallDispMin > 0 )
    {
        CallDispSec++;
        if ( CallDispSec > 59 )
        {
            CallDispSec = 0;
            CallDispMin--;
        }
    }
    else 
    {
        CallDispSec = 0;
    }
}


